import { searchFormProps } from "@/components/SearchForm/interface";
import { ProTableValue } from "@/interface/public";
/**
 * @name 查询条件 线体+key
 */

/**
 * @param {Ref} proTableBox 表格的ref
 * @description 自定义搜索条件
 */

interface BasicSearchForm {
  key: string;
  id: string;
  line: string;
  pageNum: string;
  pageSize: string;
}

export const useCustomSearchForm2 = (proTableBox: ProTableValue, changeLine?: Function) => {
  const searchForm = reactive<searchFormProps<BasicSearchForm>>({
    form: {
      key: "",
      line: "",
      id: "",
      pageNum: "",
      pageSize: ""
    },
    options: [
      {
        type: "input",
        label: "",
        prop: "key",
        first: true,
        hide: false,
        defaultValue: "",
        attrs: {
          placeholder: "请输入净量或包装编号",
          type: "number"
        },
        inputMethod: key => {
          searchForm.form.key = key;
          nextTick(() => {
            const _uni: any = uni;
            _uni.$u.debounce(proTableBox.value?.search, 500);
          });
        }
      },
      {
        type: "select",
        label: "线体",
        hide: !changeLine,
        prop: "line",
        children: [],
        attrs: {
          disabled: false
        },
        changeMethod: form => changeLine(form.line)
      }
    ]
  });

  return {
    searchForm
  };
};
